package com.ruoyi.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.utils.AliOSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
/**
 * 文件上传控制器
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/attach")
@Slf4j
public class AttachUploadController {
    @Autowired
    private AliOSSUtils aliOSSUtils;

    // 文件上传
    @PostMapping("/upload")
    public AjaxResult upload(MultipartFile file) throws Exception {
        log.info("文件为{}", file);
        // file 是从前端传递的文件
        if (file == null || file.isEmpty()) {
            return AjaxResult.error("上传失败，文件为空！");
        }
        String url = aliOSSUtils.upload(file);
        return AjaxResult.success(url);
    }
}
